package com.lenovo.codestatreport.jira.controller;

import com.lenovo.codestatreport.jira.model.AssigneeAndReporter;
import com.lenovo.codestatreport.jira.service.AssigneeAndReporterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import java.util.List;

/**
 * @author Howie Lu
 * @version Created at 2019/05/20
 * @description  由于数据表的变动，整个一套AssigneeAndReporter都暂时弃用掉
 */
@Controller
@RequestMapping("/asr")
public class AssigneeAndReporterController {
    @Autowired
    AssigneeAndReporterService assigneeAndReporterService;

    @RequestMapping("/FindAll")
    @ResponseBody
    List<AssigneeAndReporter> findAll(HttpServletRequest request){
        String tablename = request.getParameter("tablename");
        return assigneeAndReporterService.findAll(tablename);
    }

    @RequestMapping("/FindAllByTime")
    @ResponseBody
    List<AssigneeAndReporter> findAllByTime(HttpServletRequest request){
        String tablename = request.getParameter("tablename");
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        return assigneeAndReporterService.findAllByTime(tablename, start, end);
    }

    /**
     * 通过项目号查询所有的指标
     * @param request
     * @return
     */
    @RequestMapping("/FindAllByProjectKey")
    @ResponseBody
    List<AssigneeAndReporter> findByProjectKey(HttpServletRequest request){
        String tablename = request.getParameter("tablename");
        String projectkey = request.getParameter("projectkey");
        return assigneeAndReporterService.findByProjectKey(tablename, projectkey);
    }

    /**
     * 通过项目号查询某段时间内的指标
     * @param request
     * @return
     */
    @RequestMapping("/FindByProjectKeyByTime")
    @ResponseBody
    List<AssigneeAndReporter> findByProjectKeyByTime(HttpServletRequest request){
        String tablename = request.getParameter("tablename");
        String projectkey = request.getParameter("projectkey");
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        return assigneeAndReporterService.findByProjectKeyByTime(tablename, projectkey, start, end);
    }

    @RequestMapping("/FindAllProjects")
    @ResponseBody
    List<String> findAllProjects(HttpServletRequest request){
        String tablename = request.getParameter("tablename");
        return assigneeAndReporterService.findAllProjects(tablename);
    }

    /**
     * 查询某段时间内某员工的所有指标
     * @param request
     * @return
     */
    @RequestMapping("/FindByStaffByTime")
    @ResponseBody
    List<AssigneeAndReporter> findByStaffByTime(HttpServletRequest request){
        String tablename = request.getParameter("tablename");
        String staffId = request.getParameter("staffid");
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        return assigneeAndReporterService.findByStaffByTime(tablename, staffId, start, end);
    }
}
